var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeName: 1,
    wait_unlock_num: 0,
    surplus_unlock_num: 0,
    page: 1,
    finished: false,
    freezeCouponData: [],
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getData() {
    if (this.data.finished) return;
    app._getNetWork({
      url: app.getNetAddresss("plugin.froze-coupon.frontend.member-froze-coupon.get-list"),
      data: {
        page: this.data.page
      },
      success: (respone) => {
        console.log(respone,'respone')
        if (respone.data.result !== 1) {
          wx.showToast({
            title: respone.data.msg,
          });
          return false;
        }
        let res = respone.data.data;
        let finished = false;
        let freezeCouponData = [];
        let total = 1;
        freezeCouponData = this.data.freezeCouponData.concat(res.list.data);
        if (res.list.data.length === 0 || res.list.data.length < res.list.per_page || res.list.current_page === res.list.last_page) {
          finished = true;
        }
        total = res.list.total;
        
        this.setData({
          finished,
          freezeCouponData,
          page: ++this.data.page,
          total,
          surplus_unlock_num: res.surplus_unlock_num,
          wait_unlock_num: res.wait_unlock_num
        });
      }
    });
  },
})